home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / GVECTORS.ZIP / GVECTORS.DOC < prev    next >
Text File  |  1995-05-28  |  6KB  |  113 lines

  1.                                Gouraud Vectors
  2.                                       by
  3.                          Tumblin / Bodies In Motion
  4.                       ================================
  5.  
  6.      Hi there everybody.  I'm back with another source code release, and
  7. this time its on gouraud shading.  Actually I learned how to do gouraud
  8. shading when I was at NAID '95.  (Incidentally, try checking out squ.zip,
  9. Squishtro by Dungeon Dwellers Design's production for the intro competition
  10. at NAID... there is a picture of me getting squished all around with a coding
  11. carrot in my mouth! hahahahah, long story :)
  12.  
  13.      Anyway, I am not going to try to describe how to do the 3d polygon
  14. stuff that you see on the screen... it would take too long, so I will just
  15. try to explain a little bit about the gouraud shading algorithm.  Lets get
  16. started.
  17.  
  18.      Gouraud shading is a multiple step process.  When you call a routine
  19. that would draw a gouraud shaded triangle, you pass the x, y, and color of
  20. all three tips of the triangle.  Now, with this information you have to trace
  21. each of the three edges and record the coordinates and the color information
  22. along the way.  What you are trying to do is interpolate from color A to
  23. color B.  The way you do this is you calculate the amount of change in color
  24. divided by the amount of change in the distance you have to trace the edge.
  25. This will give you something similar to the slope of a line, only you are
  26. dealing with color rather than just plain x's and y's.  What you do with the
  27. slope is you add it to your screen coordinate and when it comes time to
  28. record the information, truncate off the fractional part.  You can do this by
  29. using floating point (as I have used in my source code, because I was a
  30. little lazy) or fixedpoint.  I didn't bother to optimize the routine because
  31. it would just get in the way of learning how the algorithm works, which is
  32. my purpose for releasing this anyway (:
  33.  
  34.      After you have all three edges of the triangle traced and the
  35. coordinates, and color information are recorded for each scanline
  36. (horizontally or vertically, your choice... I chose to fill my scanlines
  37. horizontally in the source code that I have included here), you have to fill
  38. between one edge of the scanline and the opposite edge of the scanline.  The
  39. filling is again done the same way as above, only you actually draw the point
  40. rather than record it into a buffer.
  41.  
  42.      Once you have all of the scanlines filled, you have drawn a gouraud
  43. shaded triangle!  Of course you could take this many steps further and create
  44. a routine that draws arbitrarily sided polygons, or many other interesting
  45. things.
  46.  
  47.      Okay, so how do you come up with the color of the vertices of the
  48. polygons you are trying to draw?  Well, in my code I did a simple little
  49. hack that not entirely correct, but still produces some funky gouraud shaded
  50. objects (:  What I did was take each vertex in the object and multiply it by
  51. 2 to generate vertex normals.  Then when I spin the object around, I also
  52. spin the normal vertices around as well.  When it comes time to draw the
  53. polygons, I take the dot product of the vertex normals and the light source
  54. and calculate a color with a little formula.  This is the same idea as
  55. lambert shading, only you apply it to each vertex normal, rather than to the
  56. one normal for the whole polygon.
  57.  
  58.      I hope this becomes more clear when you look at the source code.  Oh,
  59. I thought I might let you know that I use a tab setting of 2 in all my source
  60. code, so you may want to set your editor's tab setting to match it.
  61.  
  62.      Here are some tips to get it to compile:
  63. - Unzip all the files from this release into a directory
  64. - Open a project file (I used Turbo C++ 3.0 to compile the demo)
  65. - In the project file, include gvectors.cpp, fixedl.asm, and xlib61l.lib
  66. - Make sure that you have the compiler set to the LARGE memory model
  67. - One thing that I did with the way I organized my copy of the XLIB library
  68.   was that I copied all the *.h files into the directory I made called
  69.   c:\tc\xlib61, then I added it to compiler's include and link directories
  70.   in the Options/Directories menu.  This allows me to simply put
  71.   #include <xlib_all.h> at the top of my programs, rather than having all
  72.   those *.h files cluttering up my source code directory.  I still copied
  73.   the xlib61l.lib file to my source code directory however.  Works out great!
  74. - That should do it (:  If you have any problems, just email me.
  75.  
  76.  
  77.      The V10 objects were all created in my vector editor called
  78. VED v1.0, which I released at NAID'95.  Here's where you can find it: 
  79. ftp.cdrom.com:/pub/demos/code/utils/ved10.zip
  80.  
  81.      The gvectors.h file which contains all the palette data was created   
  82. by my PCX to C++ source code convertor.  You can find that on:
  83. ftp.cdrom.com:/pub/demos/code/images/pcx2csrc.zip.  I used Deluxe Paint to
  84. create a PCX file with the color number range 16 to 96 to be bright red to
  85. black.  Then I deleted the information about the bitmap at the top of the
  86. file and renamed the palette buffer for this program.  Quite a useful
  87. little utility I wrote!
  88.  
  89.  
  90.      I guess I'll wrap up this text file with some greets, so here they go:
  91. Dungeon Dwellers Design - Thanks for squishing my face at NAID! hehe.
  92. CORE - Your demo has been an inspiration to me.  Thanks for letting me hang
  93.        with you guys at NAID.
  94. Ronski - glad to hear that you're alive and well, give me a ring more often!
  95. Necros - too bad I didn't get to meet you, but saw you on the big stage...
  96.          congratulations for your sucess at NAID'95, I loved your song!
  97. Boggart - thanks for showing me your code and for explaining gouraud shading
  98. Voltaire - your release on gouraud shading helped a lot in making this
  99. MikMak - I like your music system, very nice
  100. Complex - your DOPE demo rocks (:
  101. Everyone I talk to on IRC in #coders :
  102. ae, johnson, fYSx, ReDDoG, anixter, MrBeach, Kodiak, Addict, Snowman, ior,
  103. Hasty, and Lord Logics.
  104.  
  105.  
  106.      Have fun with the code and we might have some more sources for ya in the
  107. not too distant future.  Until then, keep on coding, and keep on eating your
  108. coding carrots!
  109.  
  110. Tumblin / Bodies In Motion '95
  111. tumblin@mi.net
  112.  
  113.